class LineItem < ActiveRecord::Base
	belongs_to :cart
	belongs_to :product
  belongs_to :order

	

	def total_price
		quantity*product.price
	end

	def decrement_quantity(line_item_id)
    current_item = LineItem.find_by_id(line_item_id)

    current_item.quantity > 1? current_item.quantity -= 1:current_item.destroy
    # if current_item.quantity > 1
    #   current_item.quantity -= 1
    # else
    #   current_item.destroy
    # end

    current_item
  end

  def self.decrement(item)
  	# if item.quantity>1
   #    item.quantity-=1
   #  else
   #    item.destroy
   #  end
   item.quantity >1 ?item.quantity-=1:item.destroy
  end

  def self.increment(item)
  	item.quantity+=1
  end
end
